package cn.bytecollege.admin.filter;

import cn.bytecollege.common.constant.Resource;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author zsm
 * 静态资源过滤器，用于将请求/admin/static/*静态资源的请求转发至WEB-INF目录下
 */
@WebFilter(filterName = "AdminResourcesFilter",urlPatterns = "/admin/static/*")
public class AdminResourcesFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }
    public void destroy() {
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        //获取请求资源的路径
        String uri = req.getRequestURI();
        //将请求转发到对应的目录下
        request.getRequestDispatcher(Resource.PAGE_LOCATION+uri).forward(request,response);
    }
}
